<%
# Copyright (C) 2015 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<% if aac.try(:last_timeout_failure).present? %>
<p class='last_timeout_failure'>
  <%= t :ldap_timeout_failure_help2,
        "If Canvas times out too many times communicating with the LDAP server,"\
          " it will block further login attempts from using that LDAP "\
          "server for %{time}. Your LDAP server last timed out at %{timestamp}.",
        time: distance_of_time_in_words(aac.failure_wait_time),
        timestamp: datetime_string(aac.last_timeout_failure) %>
</p>
<% end %>

<div class="ic-Form-control">
  <%= f.label :auth_host, t('Host'), class: 'ic-Label', for: "auth_host_#{presenter.id_suffix(aac)}" %>
  <%= f.text_field :auth_host, class: 'ic-Input', id: "auth_host_#{presenter.id_suffix(aac)}" %>
</div>
<div class="ic-Form-control">
  <%= f.label :auth_port, t('Port'), class: 'ic-Label', for: "auth_port_#{presenter.id_suffix(aac)}" %>
  <%= f.text_field :auth_port, class: 'ic-Input', style: 'width: 50px;', id: "auth_port_#{presenter.id_suffix(aac)}" %>
</div>
<fieldset class="ic-Fieldset ic-Fieldset--radio-checkbox">
  <legend class="ic-Legend">
    {{#t}}TLS{{/t}}
  </legend>
  <div class="ic-Form-control ic-Form-control--radio">
    <div class="ic-Radio">
      <%= f.radio_button :auth_over_tls, 'start_tls', id: "start_tls_#{presenter.id_suffix(aac)}", checked: aac.auth_over_tls == 'start_tls' %>
      <%= f.label :auth_over_tls, t('Start TLS'), for: "start_tls_#{presenter.id_suffix(aac)}", class: 'ic-Label' %>
    </div>
    <div class="ic-Radio">
      <%= f.radio_button :auth_over_tls, 'simple_tls', id: "simple_tls_#{presenter.id_suffix(aac)}", checked: aac.auth_over_tls == 'simple_tls' %>
      <%= f.label :auth_over_tls, t('Simple TLS'), for: "simple_tls_#{presenter.id_suffix(aac)}", class: 'ic-Label' %>
    </div>
    <div class="ic-Radio">
      <%= f.radio_button :auth_over_tls, false, id: "no_tls_#{presenter.id_suffix(aac)}", checked: !aac.auth_over_tls %>
      <%= f.label :auth_over_tls, t('No TLS'), for: "no_tls_#{presenter.id_suffix(aac)}", class: 'ic-Label' %>
    </div>
  </div>
</fieldset>
<div class="ic-Form-control">
  <%= f.label :auth_base, t('Base'), class: 'ic-Label', for: "auth_base_#{presenter.id_suffix(aac)}" %>
  <%= f.text_field :auth_base, class: 'ic-Input', id: "auth_base_#{presenter.id_suffix(aac)}" %>
</div>
<div class="ic-Form-control">
  <%= f.label :auth_filter, t('Filter'), class: 'ic-Label', for: "auth_filter_#{presenter.id_suffix(aac)}" %>
  <%= f.text_field :auth_filter, class: 'ic-Input', id: "auth_filter_#{presenter.id_suffix(aac)}" %>
  <div class="ic-Form-help-text">
    <%= t(:auth_filter_description,
          "Use *%{placeholder}* as a placeholder for the username "\
          "supplied by the user. \nFor example: "\
          "*(sAMAccountName=%{placeholder})*",
          placeholder: '{{login}}',
          wrapper: '<code>\1</code>') %>
  </div>
</div>
<div class="ic-Form-control">
  <%= f.label :identifier_format, t('Login Attribute'), class: 'ic-Label', for: "identifier_format_#{presenter.id_suffix(aac)}" %>
  <%= f.text_field :identifier_format, class: 'ic-Input', id: "identifier_format_#{presenter.id_suffix(aac)}" %>
  <div class="ic-Form-help-text">
    <%= t(:identifer_format_description,
          "The LDAP attribute to use to look up the Canvas login. "\
          "Leave blank to use the username supplied by the user.") %>
  </div>
</div>
<div class="ic-Form-control">
  <%= f.label :auth_username, t('Username'), class: 'ic-Label', for: "auth_username_#{presenter.id_suffix(aac)}" %>
  <%= f.text_field :auth_username, class: 'ic-Input', id: "auth_username_#{presenter.id_suffix(aac)}" %>
</div>
<div class="ic-Form-control">
  <%= f.label :auth_password, t('Password'), class: 'ic-Label', for: "auth_password_#{presenter.id_suffix(aac)}" %>
  <%= f.password_field :auth_password, class: 'ic-Input', id: "auth_password_#{presenter.id_suffix(aac)}" %>
</div>
<%= render partial: 'jit_provisioning_field', locals: { aac: aac, presenter: presenter, f: f } %>
